/*
 * Copyright (c) KylinSoft Co., Ltd. 2024-2025.All rights reserved.
 * storprototrace is licensed under the Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#include <sys/stat.h>
#include <gtest/gtest.h>
#include "common.h"
#include <stdio.h>
#include <string.h>

TEST(storprototrace, op_is_write)
{
	EXPECT_EQ(op_is_write(10), 0);
	EXPECT_EQ(op_is_write(5), 1);
}

TEST(storprototrace, filt_targetname_print_stats)
{
	struct iscsi_stats stats;
	memset(&stats, 0, sizeof(stats));
	strcpy(stats.target_name, "iqn.2012-01.com.openeuler");

	EXPECT_EQ(filter_targetname_print_stats(&stats, "iqn.2012-01.com.openeuler"), 0);
	EXPECT_EQ(filter_targetname_print_stats(&stats, "iqn.2013-01.com.openeuler"), 1);
}

TEST(storprototrace, filt_initiatorname_print_stats)
{
	struct iscsi_stats stats;
	memset(&stats, 0, sizeof(stats));
	strcpy(stats.initiator_name, "iqn.2024-12.com.openeuler");

	EXPECT_EQ(filter_initiatorname_print_stats(&stats, "iqn.2024-12.com.openeuler"), 0);
	EXPECT_EQ(filter_initiatorname_print_stats(&stats, "iqn.2024-11.com.openeuler"), 1);
}

TEST(storprototrace, filter_sid_print_stats)
{
	struct iscsi_stats stats;
	memset(&stats, 0, sizeof(stats));
	stats.sid=123;

	EXPECT_EQ(filter_sid_print_stats(&stats, 123), 0);
	EXPECT_EQ(filter_sid_print_stats(&stats, 234), 1);
}

TEST(storprototrace, filter_cid_print_stats)
{
	struct iscsi_stats stats;
	memset(&stats, 0, sizeof(stats));
	stats.cid=123;

	EXPECT_EQ(filter_cid_print_stats(&stats, 123), 0);
	EXPECT_EQ(filter_cid_print_stats(&stats, 234), 1);
}

int main(int argc, char *argv[])
{
	::testing::InitGoogleTest(&argc, argv);
	return RUN_ALL_TESTS();
}
